package org.hxzon.tapestry5.pages;

import java.math.BigDecimal;

import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.services.PropertyOutputContext;
import org.hxzon.util.DateFormatUtil;

public class ExPropertyDisplayBlocks {
    @Property
    @Environmental
    private PropertyOutputContext context;

    public BigDecimal getCurrencyValue() {
        return (BigDecimal) context.getPropertyValue();
    }

    private String subStringValue(int start, int end) {
        try {
            String value = (String) context.getPropertyValue();
            value = value.substring(start, end);
            return value;
        } catch (Exception e) {
            return "";
        }
    }

    public String getDayValue() {
        return subStringValue(0, DateFormatUtil.UnitePattern_day.length());
    }

    public String getTimeValue() {
        return subStringValue(DateFormatUtil.UnitePattern_day.length() + 1, DateFormatUtil.UnitePattern_second.length());
    }

    public String getDaytimeValue() {
        return subStringValue(0, DateFormatUtil.UnitePattern_second.length());
    }

    public String getNanotimeValue() {
        return (String) context.getPropertyValue();
    }

    public String getHtmlValue() {
        return (String) context.getPropertyValue();
    }
}
